package com.itic.mall.system.orders.aftersale.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.mall.system.inter.orders.aftersale.persistence.dao.OrdersAftersaleDao;
import com.itic.mall.system.inter.orders.aftersale.persistence.model.OrdersAftersale;
import com.itic.mall.system.inter.orders.aftersale.persistence.model.OrdersAftersaleExample;
import com.itic.mall.system.inter.orders.aftersale.persistence.model.OrdersAftersaleExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class OrdersAftersaleService
     extends CrudService<OrdersAftersaleDao,OrdersAftersale,OrdersAftersaleExample> {
    @Autowired
    private OrdersAftersaleDao ordersAftersaleDao;

    
    public OrdersAftersale getDealStateByUserIdAndSkuId(String userId,String skuId,String orderNo) {
    	OrdersAftersaleExample example = new OrdersAftersaleExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andUserIdEqualTo(userId);
    	criteria.andGoodsIdEqualTo(skuId);
    	criteria.andOrderNoEqualTo(orderNo);
    	List<OrdersAftersale> aftersales = this.list(example);
    	if(aftersales.isEmpty())
    		return null;
    	else
    		return aftersales.get(0);
    }
    
    public List<OrdersAftersale> getafterSaleListByUserId(String userId) {
    	OrdersAftersaleExample example = new OrdersAftersaleExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andUserIdEqualTo(userId);
    	List<OrdersAftersale> aftersales = this.list(example);
    	return aftersales;
    }
    

}